<?php

class UserProvidor extends MrMongoDocument {
	public $pid;
	public $uid;
	public $puid;
	public $type;
	public $aKey;
	public $sKey;
	public $pub = false;
	
	public function primaryKey() {
		return 'pid,uid,puid';
	}
	public function rules() {
		return array (
//			array ('uid', 'default', 'value' => Yii::app ()->user->uid, 'on' => 'insert' ) 
		);
	}
	/**
	 * 
	 */
	public function getCollectionName() {
		return 'user_providors';
	}
	
	/**
	 * This method have to be defined in every model, like with normal CActiveRecord
	 */
	public static function model($className = __CLASS__) {
		return parent::model ( $className );
	}
	
	/**
	 * find user by providor id and providor user id.
	 * @param unknown_type $pid
	 * @param unknown_type $puid
	 */
	public static function findByPuid($pid,$puid){
		return self::model()->findByAttributes(array('pid'=>$pid,'puid'=>$puid));
	}
	
	public static function findAllByUid($uid){
		$uid = new MongoId($uid);
		return self::model()->findAllByAttributes(array('uid'=>$uid));
	}
  public static function findAllByUidPid($uid,$pid){
    $uid = new MongoId($uid);
    return self::model()->findAllByAttributes(array('uid'=>$uid,'pid'=>$pid));
  }
}
?>